#include "Server/include/Response.h"

void ResponseHead::setStatus(int status){
    this->status=status;
}
void ResponseHead::setText(std::string text){
    this->text=text;
}

void ResponseHead::setDescribe(std::string describe){
    this->describe=describe;
}


void ResponseHead::setVersion_self(const std::string& version){
    this->version=version;
}

void ResponseHead::setVersion(std::string version){
    this->version=version;
}


void ResponseHead::setMsg(std::string key,std::string value){
    this->msg.insert(std::pair<std::string,std::string>(key,value));
}

void ResponseHead::clear(){
    this->msg.clear();
}

std::string Response::returnResponse(){
    std::string s=pesHead.version;
    s.append(" ");
    s.append(std::to_string(pesHead.status));
    s.append(" ");
    s.append(pesHead.describe);
    s.append("\r\n");
    for(auto t=pesHead.msg.begin();t!=pesHead.msg.end();t++){
        s.append(t->first);
        s.append(":");
        s.append(t->second);
        s.append("\r\n");
    }
    s.append("\r\n");
    s.append(pesHead.text);
    size=s.size();
    return s;
}

void Response::setStatus(int status){
    pesHead.setStatus(status);
}
void Response::setText(std::string text){
    pesHead.setText(text);
    pesHead.setMsg("Content-Lent",std::to_string(text.size()));
}

void Response::setDescribe(std::string describe){
    pesHead.setDescribe(describe);
}


void Response::setVersion_self(const std::string& version){
    pesHead.setVersion(version);
}
void Response::setVersion(std::string version){
    pesHead.setVersion(version);
}

void Response::setMsg(std::string key,std::string value){
    pesHead.setMsg(key,value);
}

void Response::clear(){
    pesHead.clear();
}
